/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ventana2.java
 *
 * Created on 07-may-2012, 12:36:36
 */
package gui;

import javax.swing.JOptionPane;
import src.Core;

/**
 *
 * @author usuario_local
 */
public class Ventana2 extends javax.swing.JFrame {

    private Ventana1 v1;
    
    /** Creates new form Ventana2 */
    public Ventana2(Ventana1 v1) {
        this.v1 = v1;
        initComponents();
    }

    private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_v2titulo.getText().equals(""))
            mensaje += "Por favor rellene el campo de titulo\n\n";
        if (this.jTextField_v2descripcion.getText().equals(""))
            mensaje += "Por favor rellene el campo de descripción\n\n";
        if (this.jTextField_v2PCNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo del nombre de las palabras clave\n\n";
        if (!parsearURI(this.jTextField_v2PCURI.getText()))
            mensaje += "Por favor rellene el campo del URI de las palabras clave con una dirección valida\n e.j. C:.ejemplo\n"
                    + "Los . diferencian carpetas\n\n";
        if(this.jTextField_v2FNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre de los ficheros \n\n";
        if(!parsearURI(this.jTextField_v2FURI.getText()))
            mensaje += "Por favor rellene el campo del URI de los ficheros con una dirección valida\n e.j. C:.ejemplo\n"
                    + "Los . diferencian carpetas\n\n";
        
        if ("".equals(mensaje))
            resultado =true;
        else
            JOptionPane.showMessageDialog(null, mensaje);
        
        return resultado;
    }
    
    private boolean parsearURI(String uri){
        boolean resultado = false;
        
        if(!uri.equals("") && (uri.length() > 2))
            if(uri.charAt(1) == ':' && uri.charAt(2) == '.')
                resultado = true;
        
        return resultado;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel_v2titulo = new javax.swing.JLabel();
        jTextField_v2titulo = new javax.swing.JTextField();
        jLabel_v2descripcion = new javax.swing.JLabel();
        jTextField_v2descripcion = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel_v2palClave = new javax.swing.JLabel();
        jLabel_v2PCNombre = new javax.swing.JLabel();
        jTextField_v2PCNombre = new javax.swing.JTextField();
        jComboBox_v2PCTipo = new javax.swing.JComboBox();
        jLabel_v2PCTipo = new javax.swing.JLabel();
        jLabel_v2PCURI = new javax.swing.JLabel();
        jTextField_v2PCURI = new javax.swing.JTextField();
        jComboBox_v2PCFormato = new javax.swing.JComboBox();
        jLabel_v2PCFuente = new javax.swing.JLabel();
        jComboBoxv2PCFuente = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel4 = new javax.swing.JPanel();
        jLabel_v2fichero = new javax.swing.JLabel();
        jLabel_v2FNombre = new javax.swing.JLabel();
        jTextField_v2FNombre = new javax.swing.JTextField();
        jLabel_v2PCURI1 = new javax.swing.JLabel();
        jTextField_v2FURI = new javax.swing.JTextField();
        jComboBox_v2FFormato = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jButton_v2aceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Crear Documento");
        setName("Crear Documento");

        jLabel_v2titulo.setText("Titulo");

        jLabel_v2descripcion.setText("Descripcion");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel_v2titulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2titulo, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel_v2descripcion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2descripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2titulo)
                    .addComponent(jTextField_v2titulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2descripcion)
                    .addComponent(jTextField_v2descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel_v2palClave.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_v2palClave.setText("Palabras Clave");

        jLabel_v2PCNombre.setText("Nombre");

        jComboBox_v2PCTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lista de Valores", "Taxonomia", "Tesauro" }));

        jLabel_v2PCTipo.setText("Tipo");

        jLabel_v2PCURI.setText("URI");

        jComboBox_v2PCFormato.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".txt", ".pdf", ".word" }));

        jLabel_v2PCFuente.setText("Fuente");

        jComboBoxv2PCFuente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Comic Sans", "Trebuchett" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel_v2PCNombre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2PCNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel_v2PCURI)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2PCURI, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox_v2PCFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel_v2palClave)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel_v2PCTipo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox_v2PCTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel_v2PCFuente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBoxv2PCFuente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_v2palClave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2PCNombre)
                    .addComponent(jTextField_v2PCNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2PCTipo)
                    .addComponent(jComboBox_v2PCTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_v2PCFuente)
                    .addComponent(jComboBoxv2PCFuente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2PCURI)
                    .addComponent(jTextField_v2PCURI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_v2PCFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel_v2fichero.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_v2fichero.setText("Fichero");

        jLabel_v2FNombre.setText("Nombre");

        jLabel_v2PCURI1.setText("URI");

        jComboBox_v2FFormato.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".txt", ".pdf", ".word" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_v2fichero)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel_v2FNombre)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2FNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel_v2PCURI1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_v2FURI, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox_v2FFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_v2fichero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2FNombre)
                    .addComponent(jTextField_v2FNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_v2PCURI1)
                    .addComponent(jTextField_v2FURI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_v2FFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jButton_v2aceptar.setText("Aceptar");
        jButton_v2aceptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_v2aceptarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton_v2aceptar))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton_v2aceptar)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_v2aceptarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_v2aceptarMouseClicked
        // TODO add your handling code here:
        if(comprobar())
        {
        Ventana3 ventana3 = new Ventana3(v1);
        ventana3.setVisible(true);
        this.setVisible(false);
        int idFichero = Core.CrearFichero(jTextField_v2FNombre.getText(), jTextField_v2FURI.getText(), jComboBox_v2FFormato.getSelectedItem().toString());
        int idCatalogacion = Core.CrearCatalogacion(jTextField_v2PCNombre.getText(), jTextField_v2PCURI.getText(), 
                                                    jComboBox_v2PCFormato.getSelectedItem().toString(), jComboBox_v2PCTipo.getSelectedItem().toString(), 
                                                    jComboBoxv2PCFuente.getSelectedItem().toString());
        Core.CrearDocumento(jTextField_v2titulo.getText(), jTextField_v2descripcion.getText(), idFichero, idCatalogacion);
        this.dispose();
        }     
    }//GEN-LAST:event_jButton_v2aceptarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_v2aceptar;
    private javax.swing.JComboBox jComboBox_v2FFormato;
    private javax.swing.JComboBox jComboBox_v2PCFormato;
    private javax.swing.JComboBox jComboBox_v2PCTipo;
    private javax.swing.JComboBox jComboBoxv2PCFuente;
    private javax.swing.JLabel jLabel_v2FNombre;
    private javax.swing.JLabel jLabel_v2PCFuente;
    private javax.swing.JLabel jLabel_v2PCNombre;
    private javax.swing.JLabel jLabel_v2PCTipo;
    private javax.swing.JLabel jLabel_v2PCURI;
    private javax.swing.JLabel jLabel_v2PCURI1;
    private javax.swing.JLabel jLabel_v2descripcion;
    private javax.swing.JLabel jLabel_v2fichero;
    private javax.swing.JLabel jLabel_v2palClave;
    private javax.swing.JLabel jLabel_v2titulo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextField_v2FNombre;
    private javax.swing.JTextField jTextField_v2FURI;
    private javax.swing.JTextField jTextField_v2PCNombre;
    private javax.swing.JTextField jTextField_v2PCURI;
    private javax.swing.JTextField jTextField_v2descripcion;
    private javax.swing.JTextField jTextField_v2titulo;
    // End of variables declaration//GEN-END:variables
}
